<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tk_GetImage manual page - Tk Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk C API</a> <small>&gt;</small> GetImage</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="GetImage.htm#M2" NAME="L323">NAME</A>
<DL><DD>Tk_GetImage, Tk_RedrawImage, Tk_SizeOfImage, Tk_FreeImage &mdash; use an image in a widget</DD></DL>
<DD><A HREF="GetImage.htm#M3" NAME="L324">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tk.h&gt;</B>
<DD>Tk_Image
<DD><B>Tk_GetImage</B>(<I>interp, tkwin, name, changeProc, clientData</I>)
<DD><B>Tk_RedrawImage</B>(<I>image, imageX, imageY, width, height, drawable, drawableX, drawableY</I>)
<DD><B>Tk_SizeOfImage</B>(<I>image, widthPtr, heightPtr</I>)
<DD><B>Tk_FreeImage</B>(<I>image</I>)
</DL>
<DD><A HREF="GetImage.htm#M4" NAME="L325">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="GetImage.htm#M5" NAME="L326">DESCRIPTION</A>
<DD><A HREF="GetImage.htm#M6" NAME="L327">SEE ALSO</A>
<DD><A HREF="GetImage.htm#M7" NAME="L328">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tk_GetImage, Tk_RedrawImage, Tk_SizeOfImage, Tk_FreeImage &mdash; use an image in a widget
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tk.h&gt;</B><BR>
Tk_Image<BR>
<B>Tk_GetImage</B>(<I>interp, tkwin, name, changeProc, clientData</I>)<BR>
<B>Tk_RedrawImage</B>(<I>image, imageX, imageY, width, height, drawable, drawableX, drawableY</I>)<BR>
<B>Tk_SizeOfImage</B>(<I>image, widthPtr, heightPtr</I>)<BR>
<B>Tk_FreeImage</B>(<I>image</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (in)<DD>
Place to leave error message.
<P><DT><A HREF="../TkLib/WindowId.htm">Tk_Window</A> <B>tkwin</B> (in)<DD>
Window in which image will be used.
<P><DT>const char <B>*name</B> (in)<DD>
Name of image.
<P><DT>Tk_ImageChangedProc <B>*changeProc</B> (in)<DD>
Procedure for Tk to invoke whenever image content or size changes.
<P><DT>ClientData <B>clientData</B> (in)<DD>
One-word value for Tk to pass to <I>changeProc</I>.
<P><DT>Tk_Image <B><A HREF="../TkCmd/image.htm">image</A></B> (in)<DD>
Token for image instance;  must have been returned by a previous
call to <B>Tk_GetImage</B>.
<P><DT>int <B>imageX</B> (in)<DD>
X-coordinate of upper-left corner of region of image to redisplay
(measured in pixels from the image's upper-left corner).
<P><DT>int <B>imageY</B> (in)<DD>
Y-coordinate of upper-left corner of region of image to redisplay
(measured in pixels from the image's upper-left corner).
<P><DT>int <B>width</B> ((in))<DD>
Width of region of image to redisplay.
<P><DT>int <B>height</B> ((in))<DD>
Height of region of image to redisplay.
<P><DT>Drawable <B>drawable</B> (in)<DD>
Where to display image.  Must either be window specified to
<B>Tk_GetImage</B> or a pixmap compatible with that window.
<P><DT>int <B>drawableX</B> (in)<DD>
Where to display image in <I>drawable</I>: this is the x-coordinate
in <I>drawable</I> where x-coordinate <I>imageX</I> of the image
should be displayed.
<P><DT>int <B>drawableY</B> (in)<DD>
Where to display image in <I>drawable</I>: this is the y-coordinate
in <I>drawable</I> where y-coordinate <I>imageY</I> of the image
should be displayed.
<P><DT>int <B>widthPtr</B> (out)<DD>
Store width of <I>image</I> (in pixels) here.
<P><DT>int <B>heightPtr</B> (out)<DD>
Store height of <I>image</I> (in pixels) here.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
These procedures are invoked by widgets that wish to display images.
<B>Tk_GetImage</B> is invoked by a widget when it first decides to
display an image.
<I>name</I> gives the name of the desired image and <I>tkwin</I>
identifies the window where the image will be displayed.
<B>Tk_GetImage</B> looks up the image in the table of existing
images and returns a token for a new instance of the image.
If the image does not exist then <B>Tk_GetImage</B> returns NULL
and leaves an error message in interpreter <I>interp</I>'s result.
<P>
When a widget wishes to actually display an image it must
call <B>Tk_RedrawImage</B>, identifying the image (<I>image</I>),
a region within the image to redisplay (<I>imageX</I>, <I>imageY</I>,
<I>width</I>, and <I>height</I>), and a place to display the
image (<I>drawable</I>, <I>drawableX</I>, and <I>drawableY</I>).
Tk will then invoke the appropriate image manager, which will
display the requested portion of the image before returning.
<P>
A widget can find out the dimensions of an image by calling
<B>Tk_SizeOfImage</B>:  the width and height will be stored
in the locations given by <I>widthPtr</I> and <I>heightPtr</I>,
respectively.
<P>
When a widget is finished with an image (e.g., the widget is
being deleted or it is going to use a different image instead
of the current one), it must call <B>Tk_FreeImage</B> to
release the image instance.
The widget should never again use the image token after passing
it to <B>Tk_FreeImage</B>.
There must be exactly one call to <B>Tk_FreeImage</B> for each
call to <B>Tk_GetImage</B>.
<P>
If the contents or size of an image changes, then any widgets
using the image will need to find out about the changes so that
they can redisplay themselves.
The <I>changeProc</I> and <I>clientData</I> arguments to
<B>Tk_GetImage</B> are used for this purpose.
<I>changeProc</I> will be called by Tk whenever a change occurs
in the image;  it must match the following prototype:
<PRE>typedef void <B>Tk_ImageChangedProc</B>(
        ClientData <I>clientData</I>,
        int <I>x</I>,
        int <I>y</I>,
        int <I>width</I>,
        int <I>height</I>,
        int <I>imageWidth</I>,
        int <I>imageHeight</I>);</PRE>
The <I>clientData</I> argument to <I>changeProc</I> is the same as the
<I>clientData</I> argument to <B>Tk_GetImage</B>.
It is usually a pointer to the widget record for the widget or
some other data structure managed by the widget.
The arguments <I>x</I>, <I>y</I>, <I>width</I>, and <I>height</I>
identify a region within the image that must be redisplayed;
they are specified in pixels measured from the upper-left
corner of the image.
The arguments <I>imageWidth</I> and <I>imageHeight</I> give
the image's (new) size.
<H3><A NAME="M6">SEE ALSO</A></H3>
<B><A HREF="../TkLib/CrtImgType.htm">Tk_CreateImageType</A></B>
<H3><A NAME="M7">KEYWORDS</A></H3>
<A href="../Keywords/I.htm#images">images</A>, <A href="../Keywords/R.htm#redisplay">redisplay</A>
<div class="copy">Copyright &copy; 1994 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
